package com.kelly.reflect;

import java.lang.reflect.Field;
import java.util.HashMap;

import com.kelly.reflect.axiom.AxiomEnvironment;
import com.kelly.reflect.data.DataLoad;

public class Main {

	public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
		AxiomEnvironment env = new AxiomEnvironment();
		HashMap propertiesData = new HashMap<>();
		propertiesData.put("username", "郭芳碧");
		propertiesData.put("password", "1234");
		env.setProperties(propertiesData );
		
		DataLoad dataLoad = new DataLoad(env);
		
		//第一步，获取DataLoad的父类私有变量env
		Field environmentField = DataLoad.class.getSuperclass().getDeclaredField("env");
		environmentField.setAccessible(true);
		AxiomEnvironment environment = (AxiomEnvironment) environmentField.get(dataLoad);
		System.out.println(environment);
		
		// 第二步，获取environment的父类的私有变量
		Field propertiesField = AxiomEnvironment.class.getSuperclass().getDeclaredField("properties");
		propertiesField.setAccessible(true);
		HashMap properties = (HashMap) propertiesField.get(environment);
		for(Object key : properties.keySet()){
			System.out.println("key:"+key+";"+properties.get(key));
		}
		
	}
}
